package com.shouxin.attendance.utils;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.io.InputStream;

public final class TimeConfig {

	private static class Instance {
		static TimeConfig instance = new TimeConfig();
	}

	private int forenoon;

	private int noon1;

	private int noon2;

	private int afternoon;

	private TimeConfig() {
	}

	public static TimeConfig get() {
		return Instance.instance;
	}

	public int getForenoon() {
		return forenoon;
	}

	public int getNoon1() {
		return noon1;
	}

	public int getNoon2() {
		return noon2;
	}

	public int getAfternoon() {
		return afternoon;
	}

	public void initTime(Context context) {
		try {
			InputStream inputStream = context.getAssets().open("config.json");
			int size = inputStream.available();
			byte[] buffer = new byte[size];
			inputStream.read(buffer);
			JSONObject jsonObject = JSON.parseObject(new String(buffer));
			forenoon= jsonObject.getIntValue("forenoon");
			noon1 = jsonObject.getIntValue("noon1");
			noon2 = jsonObject.getIntValue("noon2");
			afternoon = jsonObject.getIntValue("afternoon");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
